/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

/**
 *This class represents a gnome entity
 * The JPA is used to store this entity in a database
 * @author Guillaume, Yann
 */
@Entity
@NamedQueries({
    @NamedQuery(name = "findAllGnome", query = "SELECT g FROM Gnome g"),
    @NamedQuery(name = "findGnomeTypeX", query = "SELECT g FROM Gnome g WHERE g.gnomeType LIKE :type")
})
public class Gnome implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;
    private String gnomeType;
    private int numberOfGnomeAvailable;
    private Double gnomePrice;

    /**
     * Gnome constructor
     */
    public Gnome() {
    }
    /**
     *  Gnome constructor with a given type, a number of gnomes available and a price
     * @param type  type of gnome
     * @param numberAvailable   number of gnomes available
     * @param price price for one gnome
     */
    public Gnome(String type, int numberAvailable, Double price) {
        this.gnomeType = type;
        this.numberOfGnomeAvailable = numberAvailable;
        this.gnomePrice = price;
        System.out.println("gnome created type " + this.gnomeType + " nbr " + this.numberOfGnomeAvailable);
    }
    /**
     * function to get the entity id
     * @return id for this type of gnome
     */
    public Integer getId() {
        return id;
    }
    /**
     * function to set the entity id
     * @param id id for this type of gnome
     */
    public void setId(Integer id) {
        this.id = id;
    }
    /**
     * function to set the entity type
     * @param type  type for this gnome
     */
    public void setGnomeType(String type) {
        this.gnomeType = type;
    }
    /**
     *  function to get the entity type
     * @return type for this gnome
     */
    public String getGnomeType() {
        return this.gnomeType;
    }
    /**
     * function to set the number of gnome available
     * @param nbr number of gnome available
     */
    public void setNumberOfGnomeAvailable(int nbr) {
        this.numberOfGnomeAvailable = nbr;
    }
    /**
     * function to get the number of gnome available
     * @return 
     */
    public int getNumberOfGnomeAvailable() {
        return this.numberOfGnomeAvailable;
    }
    /**
     * function to set the gnome price
     * @param price 
     */
    public void setGnomePrice(Double price) {
        this.gnomePrice = price;
    }
    /**
     * function to get the gnome price
     * @return 
     */
    public Double getGnomePrice() {
        return this.gnomePrice;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Gnome)) {
            return false;
        }
        Gnome other = (Gnome) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "model.Gnome[ id=" + id + " ]";
    }
}
